package serova.valeriya.electricity;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.Properties;
import java.io.IOException;
public class Configuration {	
	private  final String LOG_PATH="LOG_PATH";
	private  final String REGISTRATION_DATA_PATH="REGISTRATION_DATA_PATH";	
	private  final String TEMPLATE_NAME="TEMPLATE_NAME";
	private  final String STAT_TEMPLATE_NAME="STAT_TEMPLATE_NAME";
	private  final String REPORT_NAME="REPORT_NAME";
	private  final String STAT_REPORT_NAME="STAT_REPORT_NAME";
	private  final String TARIFICATION_DATA_PATH="TARIFICATION_DATA_PATH";
	private static Properties obj = new Properties(); 
	private static Configuration configuration = null;
	
	public static Configuration getCurrentInstance(){
		if (null == configuration){
			configuration = new Configuration();
		}
		return configuration;
	}
		
	public Configuration(){
		try {
			init();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static void init() throws IOException{			
		//InputStreamReader stream = TariffDataSource.getInputStreamReader("conf/config.txt");
		InputStreamReader stream = null;
		try {
			
			File file = new File("src/main/resources/conf/config.txt");
			
			FileInputStream fin = new FileInputStream(file);
			stream = new InputStreamReader(fin);
		} catch (FileNotFoundException e) {
			//LOGGER.error("Ошибка источника данных. Категория в файле не найдена", e);
			UserDialog.printErrorMessage("Ошибка источника данных. Категория в файле не найдена" + e);
		}
		
		obj.load(stream);		 
	}
	public String getTarificationDataPath() {
	      return obj.getProperty(TARIFICATION_DATA_PATH).trim();
	}
	public String getLogPath() {		
	      return obj.getProperty(LOG_PATH).trim();
	}
	public String getRegistrationDataPath() {
	    String registrationDataPath = obj.getProperty(REGISTRATION_DATA_PATH);
		return null == registrationDataPath ? null : registrationDataPath.trim();
	}
	public String getTemplateName() {
	      return obj.getProperty(TEMPLATE_NAME).trim();
	}
	public String getStatTemplateName() {
	      return obj.getProperty(STAT_TEMPLATE_NAME).trim();
	}
	public String getReportName() {
	      return obj.getProperty(REPORT_NAME).trim();
	}
	public String getStatReportName() {
	      return obj.getProperty(STAT_REPORT_NAME).trim();
	}	
	
	
}

